#ifndef __MINIUTIL_FRAME_PICKLE_H__
#define __MINIUTIL_FRAME_PICKLE_H__

#include <string>
#include "miniutil/datatype.h"

namespace miniutil { namespace frame {  

    miniutil::m_uint16_t get_uint16_be(const char*);
    miniutil::m_uint32_t get_uint32_be(const char*);
    miniutil::m_uint64_t get_uint64_be(const char*);
    miniutil::m_uint16_t get_uint16_le(const char*);
    miniutil::m_uint32_t get_uint32_le(const char*);
    miniutil::m_uint64_t get_uint64_le(const char*);

    void put_uint16_be(char*, miniutil::m_uint16_t);
    void put_uint32_be(char*, miniutil::m_uint32_t);
    void put_uint64_be(char* buf, miniutil::m_uint64_t value);
    void put_uint16_le(char*, miniutil::m_uint16_t);
    void put_uint32_le(char*, miniutil::m_uint32_t);
    void put_uint64_le(char* buf, miniutil::m_uint64_t value);

    enum
    {
        PICKLE_SET = 0,
        PICKLE_CUR,
        PICKLE_END
    };

   //light read pickle without memory control
   class Pickler
   {
    public:
        Pickler(const char* pcontent, int);
        ~Pickler();
        
		int PopFront(char*);
		int PopFront(short*);
		int PopFront(int*);
		int PopFront(long long*);
		int PopFront(char*, int len);
		int PopFront(std::string *);
		    
        int SeekReadPos(int flag, int offset);		    
    private:
        int mroffset;
        int mctlen;
        const char* mpcontent;		
   };
    
   //light write pickle without memory control
   class Picklew
   {
    public:
        Picklew();
        Picklew(char* pcontent, int);

        ~Picklew();
        
        //int PushFront(char);
        //int PushFront(short);
        //int PushFront(int);
        //int PushFront(long long);
        //int PushFront(const char* , int);
        
        int PushBack(char);
        int PushBack(short);
        int PushBack(int);
        int PushBack(long long);
        int PushBack(const char* pdata, int);
        int PushBack(std::string);

        int SetValue(int, char);
        int SetValue(int, short);
        int SetValue(int, int);
        int SetValue(int, long long);
        int SetValue(int, const char*, int);
        int SetValue(int, std::string);            
        
        const char* RefData();
        const int RefDataLen();
     private:
        int mctlen;
        int mbflen;
        char* mpcontent;
        bool mselfalloc;

        int CheckRightLenOver(int);
            
   };
    
} }    


#endif
